<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
use think\Request;
use think\Loader;
class Design extends Rbac
{
//    项目设计部页面
    public function design()
    {
		$select_product = Db::name('product')->where('pro_sn',1)->paginate(10);
		$page = $select_product->render();
		$this->assign('page', $page);
		$this -> assign('select_product',$select_product);
       return $this->fetch('design/design_board');
    }

	
	
	//下属学生情况展示页面
	
	public function student()
    {
		$job_group_id = Request()->param('job_group_id');
		$select_job = Db::name('job')->where('job_group_id',$job_group_id)->paginate(10);
		$page = $select_job->render();
		$this->assign('page', $page);
		$this -> assign('select_job',$select_job);
       return $this->fetch('open/student_board');
    }
	public function student_alter()
    {
		 $job_id = request()->param('job_id');
		
		 $find_job = Db::name('job')->where('job_id',$job_id)->find();
		 
		 $this -> assign('find_job',$find_job);
		 if(!empty($_POST)){
			$job_id = $_POST['job_id'];
			$find_job = Db::name('job')->where('job_id',$job_id)->find();
			$job_study_status = !empty($_POST['job_study_status']) ? $_POST['job_study_status'] : $find_job['job_study_status'];
			$data = [
				'job_study_status' => $job_study_status,
			];
			$update_job = Db::name('job')->where('job_id',$job_id)->update($data);
			if($update_job>=0){
				$this->success('修改成功',"admin/open/student?job_group_id=".$find_job['job_group_id'] );
			}
		 }
		 
       return $this->fetch('open/student_alter');
    }
	
	//结业
	public function finish()
    {	
		$pro_id = $_POST['pro_id'];
		//$pro_id = request()->param('pro_id');
		$update_product = Db::name('product')->where('pro_id',$pro_id)->update(['pro_finish_sn'=>1,'pro_finish_time'=>time()]);
		if($update_product){
			$update_job = Db::name('job')->where('job_group_id',$pro_id)->update(['job_getjob_sn'=>1,'job_graduate_time'=>time()]);
			if($update_job){
				echo 1;
			}
		}
		
    }
	
	
	
	
	
	
	
	
	
	
	
	
    //    项目开发部人员管理
    public function person()
    {
		$select_user = Db::name('user')->where('user_r_id','13')->paginate(10);
		$page = $select_user->render();
		$this->assign('page', $page);
		$this -> assign('select_user',$select_user);
        return $this->fetch('design/person_board');
    }
	
	//    项目开发部人员管理
    public function add()
    {
		if(!empty($_POST)){
			$data = [
				'user_name' => $_POST['user_name'],
				'user_phone' => $_POST['user_phone'],
				'user_createtime' => strtotime($_POST['user_createtime']),
				'user_text' => $_POST['user_text'],
				'user_password' => sha1(md5("z123456")."mingdaima"),
				'user_r_id' => 13,
			];
			$row = Db::name('user')->insert($data);
			if($row){
				$this->success('添加成功',"admin/design/person");
			}
		}
        return $this->fetch('design/person_add');
    }
	public function alter()
    {
		$user_id = request()->param('user_id');
		 $find_user = Db::name('user')->where('user_id',$user_id)->find();
		 $this -> assign('find_user',$find_user);
		if(!empty($_POST)){
			$user_id = $_POST['user_id'];
			$find_user = Db::name('user')->where('user_id',$user_id)->find();
			$data = [
				'user_name' => (!empty($_POST['user_name'])) ? $_POST['user_name'] : $find_user['user_name'],
				'user_phone' => (!empty($_POST['user_phone'])) ? $_POST['user_phone'] : $find_user['user_phone'],
				'user_createtime' => (!empty($_POST['user_createtime'])) ? strtotime($_POST['user_createtime']) : $find_user['user_createtime'],
				'user_text' => (!empty($_POST['user_text'])) ? $_POST['user_text'] : $find_user['user_text'],
			];
			
			$update_user = Db::name('user')->where('user_id',$user_id)->update($data);
			if($update_user){
				$this->success('修改成功',"admin/design/person");
			}else{
				$this->error('至少修改一行',"admin/design/alter?user_id=".$user_id );
			}
		}
        return $this->fetch('design/person_alter');
    }
}
